package com.easyedu.signcenter.dao;

import com.easyedu.signcenter.entity.DO.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lmr
 **/
@Mapper
public interface UserDao {

    /**
     * 功能描述: 通过用户名获取用户登陆所需信息
     * @param username 1 用户名
     * @return : com.center.signcenter.entity.DO.User
     **/
    @Select("select * from user where user_name = #{username}")
    User getUserByUserName(String username);

    /**
     * 功能描述:注册学生用户，statue为可用，level为4
     *         主键值存入User类
     * @param user 1 Persistant Object
     * @return : com.center.signcenter.entity.DO.User
     **/
    @Options(useGeneratedKeys = true, keyProperty = "userid", keyColumn = "userid")
    @Insert("insert into user set user_number = #{userNumber},user_name = #{userName},password = #{password},create_time = " +
            "NOW()," +
            "update_time = NOW();")
    Integer createNewStudentUser(User user);

    /**
     * 功能描述:查询与username或userNumber相同的用户
     * @param userName 1 用户名
     * @param userNumber 2 用户编号
     * @return : java.util.List<com.center.signcenter.entity.DO.User>
     **/
    @Select("select * from user where user_number = #{userNumber} or user_name = #{userName}")
    List<User> getUserByUserNameOrUserUserNumber(String userName, Long userNumber);

    /**
     * 功能描述:查询与userNumber相同的用户
     * @param userNumber 1 用户编号
     * @return : com.center.signcenter.entity.DO.User
     **/
    @Select("select * from user where user_number = #{userNumber}")
    User getUserByUserNumber(Long userNumber);

    /**
     * 功能描述:更新上次登陆时间
     * @param userNumber 1 用户编号
     * @return : void
     **/
    @Update("update user set last_login_time = NOW() where user_number = #{userNumber}")
    void flashLoginTime(Long userNumber);

    /**
     * 功能描述:删除用户，用于测试类，实际不进行删除用户而是将用户设置为不可用
     * @param userid 1 用户id
     * @return : java.lang.Integer
     **/
    @Delete("delete from user where userid = #{userid}")
    Integer deleteUserById(long userid);
}
